<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>帖子编辑</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/index.css">
    <link rel="stylesheet" href="css/global.css">
    <link rel="stylesheet" href="css/font_24081_dddajmj0coc4n29.css">
    <link rel="stylesheet" href="layui/css/modules/layer/default/layer.css">
    <script src="js/jquery.min.js"></script>

</head>

<body>
    <div class="forum-header">
        <div class="layui-container">
            <a class="logo" href="index"><img src="img/logo.png" alt=""></a>



            <div class="fly-column-right layui-hide-xs" style="top:15px;">
                <span class="fly-search LAY_search" style="position:relative;top:8px" id="Search">
					<i class="layui-icon"></i>
				</span>
                <a href="/post/add" class="layui-btn">发表新帖</a>
            </div>

        </div>
    </div>
    <div class="layui-row layui-col-space15" style="margin-top:20px">
        <div class="layui-container">
            <div class="layui-row">
                <div class="layui-col-md8">
                    <div class="fly-panel detail-box">
                        <div  class="layui-form">
                            <div class="layui-form-item" style="width:100%;">
                                <input id="title" type="text" placeholder="请输入标题" lay-verify="title" class="layui-input" name="title" required style="width:100%;">
                            </div>
							<textarea id="content" type="text" placeholder="请输入内容" lay-verify="title" class="layui-input" name="content" required style="width:100%;height:500px;"></textarea>
                            
                            <div class="layui-form-item">
                                <button  onclick="postQuestion()" lay-submit class="layui-btn layedit-context" style="width:30%;" data-type="content" lay-filter="post">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
    </div>
    </div>



    <div class="fly-footer">
        
            <a href="#" target="_blank">关于我们</a>
            <a href="#" target="_blank">友情链接</a>
            <a href="#" target="_blank">社区小黑板</a>

    </div>
    <script src="layui/layui.js"></script>
    <script src="layui/lay/modules/layer.js"></script>
    <script src="js/index.js"></script>
    <script>
	// 获取数据
	function postQuestion() {
		var storage=window.localStorage;
		if(!storage.uid){
			alert("未登录");
			return;
		}
		var uid=Number(storage.uid);
		//console.log(uid);
		var tmp={
				uid: uid,
				title: $("#title").val(),
				content:$("#content").val()
			};
		//console.log(tmp);
		//return;
		$.ajax({
			type: "POST",
			url: "http:localhost:8080/api/question/add",
			data:JSON.stringify(tmp),
			contentType:'application/json',
			dataType: "json",
			async: false,
			success: function(data) {
				if (data.code==200) {
					window.location.replace("index.html"); 
				} else {
					alert(data.msg);
					//$.messager.alert('系统提示', data.msg);
				}
			}
		}).done().fail(function() {
			alert('服务器错误！');
		});
	};
    </script>
</body>

</html>